package ca.etsmtl.log210.vues;

import javax.swing.JDialog;
import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class GuiDemandeAdresse extends JDialog
{
	
	private static final int LARGEUR = 340;
	private static final int HAUTEUR = 256;
	
	private JTextField numeroRueField;
	private JTextField nomRueField;
	private JTextField villeField;
	private JTextField postalCodeField;
	
	public GuiDemandeAdresse() {
		setTitle("Please choose your desired delivery address");

		//Fenêtre modale
		setModalityType(JDialog.DEFAULT_MODALITY_TYPE);
		//dimension de la fenêtre
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();

		//Vous pouvez mettre les valeurs qui vous tentent pour ces constantes
		setSize(LARGEUR,HAUTEUR);

		//Position au centre de l’écran
		setLocation((d.width-LARGEUR)/2,(d.height-HAUTEUR)/2);
		setResizable(false);

		//On ne ferme pas l’application.  On enlève la fenêtre de la mémoire sur X
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		JLabel lblStreetNumber = new JLabel("Street number:");
		
		numeroRueField = new JTextField();
		numeroRueField.setColumns(10);
		
		JLabel lblStreetName = new JLabel("Street name:");
		
		nomRueField = new JTextField();
		nomRueField.setColumns(10);
		
		JLabel lblCity = new JLabel("City:");
		
		villeField = new JTextField();
		villeField.setColumns(10);
		
		JLabel lblPostalCode = new JLabel("Postal Code:");
		
		postalCodeField = new JTextField();
		postalCodeField.setColumns(10);
		
		JLabel lblEx = new JLabel("ex.:  1234");
		
		JLabel lblExBoileau = new JLabel("ex.: Boileau");
		
		JLabel lblExNewYork = new JLabel("ex.: New York");
		
		JLabel lblExJvk = new JLabel("ex.: J7V 6K4");
		
		JButton btnConfirm = new JButton("Confirm");
		
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
						.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
							.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
								.addComponent(lblStreetNumber)
								.addGap(18)
								.addComponent(numeroRueField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
							.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
								.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
									.addComponent(lblCity)
									.addComponent(lblStreetName))
								.addGap(28)
								.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
									.addComponent(nomRueField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
									.addComponent(villeField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(lblPostalCode)
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(postalCodeField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addComponent(lblEx)
						.addComponent(lblExBoileau)
						.addComponent(lblExNewYork)
						.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
							.addComponent(btnConfirm)
							.addComponent(lblExJvk)))
					.addContainerGap(169, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(21)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblStreetNumber)
						.addComponent(numeroRueField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblEx))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(nomRueField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblStreetName)
						.addComponent(lblExBoileau))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblCity)
						.addComponent(villeField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblExNewYork))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblPostalCode)
						.addComponent(postalCodeField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblExJvk))
					.addGap(18)
					.addComponent(btnConfirm)
					.addContainerGap(87, Short.MAX_VALUE))
		);
		getContentPane().setLayout(groupLayout);
		
		/*
		 * Ecouteur du bouton confirm
		 *****************************/
		btnConfirm.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				//TODO 
				dispose();
			}
		});
	}
	
	/**
	 * Methode qui retourne l'adresse demandee suite a la saisie des informations a l'ecran
	 * @return Une chaine de caractere representant l'adresse demandee
	 * 
	 */
	public String[] getAdresseDemande()
	{
		setVisible(true);
		String[] champstab = {numeroRueField.getText(), nomRueField.getText(), villeField.getText(), postalCodeField.getText()};
		return champstab;
	}
}
